#include <react/react.h>
#include <time.h>

int main() {
    rec::reactor r;
    rec::acceptor<rec::protocol::tcp> acp;
    rec::utility::set_nonblocking(acp.get_fd());
    acp.do_bind("0.0.0.0", 9090);
    acp.do_listen();

    r.add_acceptor(std::move(acp), [](int fd){
	while (1) {
	    write(fd, "hello world\n", 13);
	    sleep(1);
	}
    });

    auto sflow = rec::sigflow::instance();
    sflow->add_signal(SIGINT, [&r](){
        std::cout<<"\nReceived SIGINT and exit in 1 sec"<<std::endl;
        sleep(1);
        r.destroy();  // closed the reactor
    });
    r.add_sigflow(sflow);
    r.activate();
}
